﻿@using System.Web.UI.WebControls
@using Microsoft.Ajax.Utilities
@model Sis.Entities.Promotor

@{
    ViewBag.Title = "Create";
}

<script type="text/javascript">
    $(document).ready(function () {
        $("#NumPromotor").keypress(function (e) {

            if (e.shiftKey) {
                e.preventDefault();
            }
            else {
                var key = window.Event ? e.which : e.keyCode;
                return ((key >= 48 && key <= 57) || (key == 8) || (key == 13));

            }
        });
        $("#Telefono").keypress(function (e) {

            if (e.shiftKey) {
                e.preventDefault();
            }
            else {
                var key = window.Event ? e.which : e.keyCode;
                return ((key >= 48 && key <= 57) || (key == 8) || (key == 13));

            }
        });
        $("#CodigoPromotor").keypress(function (e) {

            if (e.shiftKey) {
                e.preventDefault();
            }
            else {
                var key = window.Event ? e.which : e.keyCode;
                return ((key >= 48 && key <= 57) || (key == 8) || (key == 13));

            }
        });
        $("#CodigoEquifax").keypress(function (e) {

            if (e.shiftKey) {
                e.preventDefault();
            }
            else {
                var key = window.Event ? e.which : e.keyCode;
                return ((key >= 48 && key <= 57) || (key == 8) || (key == 13));

            }
        });
        $("#Dni").keypress(function (e) {

            if (e.shiftKey) {
                e.preventDefault();
            }
            else {
                var key = window.Event ? e.which : e.keyCode;
                return ((key >= 48 && key <= 57) || (key == 8) || (key == 13));

            }
        });
        $('#Ubigeo').keypress(function (e) {
            if ((event.keyCode != 32) && (event.keyCode < 65) || (event.keyCode > 90) && (event.keyCode < 97) || (event.keyCode > 122))
                event.returnValue = false;
        });
        $('#Nombres').keypress(function (e) {
            if ((event.keyCode != 32) && (event.keyCode < 65) || (event.keyCode > 90) && (event.keyCode < 97) || (event.keyCode > 122))
                event.returnValue = false;
        });
        $('#ApPaterno').keypress(function (e) {
            if ((event.keyCode != 32) && (event.keyCode < 65) || (event.keyCode > 90) && (event.keyCode < 97) || (event.keyCode > 122))
                event.returnValue = false;
        });
        $('#ApMaterno').keypress(function (e) {
            if ((event.keyCode != 32) && (event.keyCode < 65) || (event.keyCode > 90) && (event.keyCode < 97) || (event.keyCode > 122))
                event.returnValue = false;
        });
        $('#Ubigeo').typeahead({
            source: function (query, process) {
                var countries = [];
                map = {};

                return $.post('/Promotor/AutoCompleteCountry', { query: query }, function (data) {

                    // Loop through and push to the array
                    $.each(data, function (i, country) {
                        map[country.Nombre] = country;
                        countries.push(country.Nombre);
                    });

                    // Process the details
                    process(countries);
                });
            },
            updater: function (item) {
                var selectedShortCode = map[item].Id;

                // Set the text to our selected id
                $("#Ubigeo").text("Selected : " + selectedShortCode);
                return item;
            }
        });
        $('#FechaNac').on('focusout', function () {

            var fechaNac = this.value;//$('#FechaNac').on('getDate'); //el var fecha nac


            fecha = new Date(fechaNac);
            hoy = new Date();
            ed = parseInt((hoy - fecha) / 365 / 24 / 60 / 60 / 1000);
            //alert("tienes " + ed + " años");
            if (ed < 18) {
                alert("ud es Menor de edad, no puede ser contrado");
            }

        });
    });
</script>


@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    
    <h1>Nuevo Registro</h1>
    <legend>
        <fieldset>Datos Promotor</fieldset>
    </legend>
    <table class="table">
        <tr>
            <td>@Html.LabelFor(model => model.CodigoPromotor)</td>
            <td>
                @Html.EditorFor(model => model.CodigoPromotor)
                @Html.ValidationMessageFor(model => model.CodigoPromotor)
            </td>
            <td>@Html.LabelFor(model => model.NumPromotor)</td>
            <td>
                @Html.EditorFor(model => model.NumPromotor)
                @Html.ValidationMessageFor(model => model.NumPromotor)
            </td>
            <td>@Html.LabelFor(model => model.Ubigeo)</td>
            <td>
                @Html.EditorFor(model => model.Ubigeo)
                @Html.ValidationMessageFor(model => model.Ubigeo)
            </td>
        </tr>
        <tr>
            <td>@Html.Label("Isla")</td>
            <td>
                @*@Html.EditorFor(model => model.IdIslaVenta)*@
                @Html.DropDownList("IdIslaVenta", null, new { @data_live_search = "true" })
                @Html.ValidationMessageFor(model => model.IdIslaVenta)
            </td>
            <td>@Html.LabelFor(model => model.CodigoEquifax)</td>
            <td>
                @Html.EditorFor(model => model.CodigoEquifax)
                @Html.ValidationMessageFor(model => model.CodigoEquifax)
            </td>            
        </tr>
    </table>
    <legend>
        <fieldset>Datos Personales</fieldset>
    </legend>
    <table class="table">
        <tr>
            <td>@Html.LabelFor(model => model.Dni)</td>
            <td>
                @Html.EditorFor(model => model.Dni)
                @Html.ValidationMessageFor(model => model.Dni)
            </td>
            <td>@Html.LabelFor(model => model.Nombres)</td>
            <td>
                @Html.EditorFor(model => model.Nombres)
                @Html.ValidationMessageFor(model => model.Nombres)
            </td>
            <td>@Html.LabelFor(model => model.ApPaterno)</td>
            <td>
                @Html.EditorFor(model => model.ApPaterno)
                @Html.ValidationMessageFor(model => model.ApPaterno)
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(model => model.ApMaterno)</td>
            <td>
                @Html.EditorFor(model => model.ApMaterno)
                @Html.ValidationMessageFor(model => model.ApMaterno)
            </td>
            <td>@Html.Label("Genero  Masculino:")</td>
            <td>
                @Html.EditorFor(model => model.Genero)
                @Html.ValidationMessageFor(model => model.Genero)
            </td>
            <td>@Html.LabelFor(model => model.FechaNac)</td>
            <td>
                @Html.EditorFor(model => model.FechaNac)
                @Html.ValidationMessageFor(model => model.FechaNac)
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(model => model.Telefono)</td>
            <td>
                @Html.EditorFor(model => model.Telefono)
                @Html.ValidationMessageFor(model => model.Telefono)
            </td>
            <td>@Html.LabelFor(model => model.email)</td>
            <td>
                @Html.EditorFor(model => model.email)
                @Html.ValidationMessageFor(model => model.email)
            </td>
            <td>@Html.LabelFor(model => model.Direccion)</td>
            <td>
                @Html.EditorFor(model => model.Direccion)
                @Html.ValidationMessageFor(model => model.Direccion)
            </td>
        </tr>
    </table>

        <p>
            <button type="submit" value="Guardar" class="btn btn-success" title="Guardar">
                <span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span> Guardar
            </button>
            @Html.ActionLink("  Atras", "Index",null , new{@class="glyphicon glyphicon-arrow-left btn btn-danger"})
        </p>
    
}


@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
